<?php
date_default_timezone_set('Asia/Saigon');
?><?php
# MantisBT - a php based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.

	/**
	 * @package MantisBT
	 * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
	 * @copyright Copyright (C) 2002 - 2010  MantisBT Team - mantisbt-dev@lists.sourceforge.net
	 * @link http://www.mantisbt.org
	 */
	 /**
	  * MantisBT Core API's
	  */
	require_once( 'core.php' );
	require_once( 'current_user_api.php' );
	require_once( 'compress_api.php' );
	require_once( 'filter_api.php' );
	require_once( 'last_visited_api.php' );
	
	auth_ensure_user_authenticated();

	$t_current_user_name = current_user_get_field( 'username' );
	
	# Improve performance by caching category data in one pass
	category_get_all_rows( helper_get_current_project() );

	compress_enable();

	# don't index my view page
	html_robots_noindex();

	html_page_top1( lang_get( 'my_view_link' ) );

	if ( current_user_get_pref( 'refresh_delay' ) > 0 ) {
		html_meta_redirect( 'my_view_page.php', current_user_get_pref( 'refresh_delay' )*60 );
	}

	html_page_top2();

	print_recently_visited();

	$f_page_number		= gpc_get_int( 'page_number', 1 );

	$t_per_page = config_get( 'my_view_bug_count' );
	$t_bug_count = null;
	$t_page_count = null;

	$t_boxes = config_get( 'my_view_boxes' );
	asort ($t_boxes);
	reset ($t_boxes);
	#print_r ($t_boxes);

	$t_project_id = helper_get_current_project();
?>

<br>
Trung tâm R&D và CMCLab<br>
=========================================================
<?php
$ip=$_SERVER['REMOTE_ADDR'];
$do = $_GET['do'];
echo "<br>[<a href=?do=checkform>CheckForm</a>]";
echo "[<a href=?do=showlistvr>Show listvirus</a>]";
echo "[<a href=?do=mDetected>Malware detected</a>]<br><br>";

//Nhập thông tin để gửi mẫu virus về CMCLab
if ($do == checkform)
{
echo '
<div>
Welcome to <b>High Priority</b> "Malware" submission service | CMC InfoSec<br><br>

We appreciate all submissions those will greatly increase our detection rate.<br>
Call us at <b>1900 571244</b> any time for <b>Human Support</b><br><br>

<table border=0 cellpadding=0 cellspacing=0 style="border-collapse:collapse"><tr>
<form action="?do=upload" method="post" enctype="multipart/form-data">
<td>Name</td><td><input type="name"  name="name" /></td></tr><tr>
<td>Email</td><td><input type="email" name="email" /></td></tr><tr>
<td>Phone</td><td><input type="phone" name="phone" /></td></tr><tr>
<td>Mô tả</td><td><textarea name="description" type="description" cols="44" rows="5"></textarea></td></tr><tr>
<td>Nhập file</td><td><input type="file"  name="ufile" /></td></tr><tr>
<td></td><td><input type="submit" value="Submit malware to CMCLab" /></td>
</tr></table>
</form>
</div>';
}

//Ghi thông tin của file gửi về
if ($do == upload)
{

	$SafeFile = $HTTP_POST_FILES['ufile']['name'];
	$SafeFile = str_replace("#", "No.", $SafeFile);
	$SafeFile = str_replace("$", "Dollar", $SafeFile);
	$SafeFile = str_replace("%", "Percent", $SafeFile);
	$SafeFile = str_replace("^", "", $SafeFile);
	$SafeFile = str_replace("&", "and", $SafeFile);
	$SafeFile = str_replace("*", "", $SafeFile);
	$SafeFile = str_replace("?", "", $SafeFile);

	$uploaddir = "malware/";
	$path = $uploaddir.$SafeFile;
		$t_current_user_name = current_user_get_field( 'username' );
	if($ufile != none){ //AS LONG AS A FILE WAS SELECTED...

    if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))//IF IT HAS BEEN COPIED...
	{ 
		//GET FILE NAME
        $theFileName = $HTTP_POST_FILES['ufile']['name'];

        //GET FILE SIZE
        $theFileSize = $HTTP_POST_FILES['ufile']['size'];
		
		//GET FILE SIZE
        $theFileType = $HTTP_POST_FILES['ufile']['type'];
		

        if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
            $theDiv = $theFileSize / 1000000;
            $theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
        } else { //OTHERWISE DISPLAY AS KB
            $theDiv = $theFileSize / 1000;
            $theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
        }
		$senderName = $_POST['name'];
		$senderPhone = $_POST['phone'];
		$senderMail = $_POST['email'];
		$fileDesciption = $_POST['description'];
		
		echo '
			<table cellpadding="5" width="300">
			<tr>
				<td align="Center" colspan="2"><font color="#009900"><b>Upload Successful</b></font></td>
			</tr>
			<tr>
				<td align="right"><b>File Name: </b></td>
				<td align="left">'.$theFileName.'</td>
			</tr>
			<tr>
				<td align="right"><b>File Size: </b></td>
				<td align="left">'.$theFileSize.'</td>
			</tr>
			<tr>
				<td align="right"><b>Directorz: </b></td>
				<td align="left">'.$uploaddir.'</td>
			</tr>
			<tr>
				<td align="right"><b>File Type: </b></td>
				<td align="left">'.$theFileType.'</td>
			</tr>
			</table>';
			echo 'Cám ơn bạn <b>'.$senderName.'</b> đã gửi mẫu virus về CMCLab <br>';
			echo 'Mẫu Malware của bạn đã được chuyển đến nhân viên phân tích virus <b>Hieunt</b><br>';
			echo 'Sau khi CMC detect được mẫu này sẽ thông báo lại cho bạn qua email hoặc điện thoại. Thanks';
			$date_added = time();
			echo '<br>Download Mẫu malware tại <a href='.$path.'>đây</a>';
			$mark = 'undetected';
			mysql_query("insert into `mantis_malware_file_table` 
			(filename,description,file_type,folder,filesize,date_added,senderName, senderMail, senderPhone, mark) 
			values ('$theFileName','$fileDesciption','$theFileType','$uploaddir','$theFileSize','$date_added','$senderName','$senderMail','$senderPhone','$mark')");
			//$receiverMail("");
	//Include send mail
	include("mail_reply_sender.php");
	include("mail_reply_receiver.php");	
	} else 
	{


//PRINT AN ERROR IF THE FILE COULD NOT BE COPIED
		echo '
		<table cellpadding="5" width="80%">
		<tr>
		<td align="Center" colspan="2"><font color=\"#C80000\"><b>File could not be uploaded</b></font></td>
		</tr></table>';
    }
	}
}

//show list virus and status of that
if ($do == showlistvr)
{
	$qrShowList = mysql_query("select id,filename,description,file_type,folder,filesize,date_added, date_complete, from_unixtime(date_added),senderName,senderMail,senderPhone,mark,cViruser,from_unixtime(date_complete) from mantis_malware_file_table");
	echo "<table border=1 cellpadding=0 cellspacing=0 style='border-collapse:collapse' align=center>";
	echo "<tr><td>ID</td><td>FID</td><td>FILENAME</td><td>TIME ADDED </td><td>TIME COMPLETE </td><td>TIME REMAIN</td><td>Engineer</td><td>DESCRIPTION</td><td>MARK</td><td>SET STATUS</td></tr>";
	$run = 0;
	while ($row = mysql_fetch_array($qrShowList))
	{
		$run++;
		$id = $row['id']; 
		$filename = $row['filename']; 
		$description = $row['description'];
		$file_type = $row['file_type'];
		$folder = $row['folder'];
		$filesize = $row['filesize'];
		$dAdd = $row['from_unixtime(date_added)'];
		$senderName = $row['senderName'];
		$senderMail = $row['senderMail'];
		$senderPhone = $row['senderPhone'];
		$mark = $row['mark'];
		$cViruser = $row['cViruser'];	
		$dComp = $row['from_unixtime(date_complete)'];
		$tA = $row['date_added'];
		$tC = $row['date_complete'];
		$tRemain = $tC - $tA;
		$number = sprintf("%01.2f", $tRemain);
		
		echo "<tr><td>$run</td><td>$id</td><td>$filename</td><td>".$dAdd."</td>
		<td>$dComp</td><td>";
		if ($number  <= 0){echo "0";}
		if (($number  <60) and ($number >0)){echo $number."s";}
		if (($number  <3600) and ($number >=60)){$t = $number/60;$n = sprintf("%01.2f", $t);echo $n." p";}
		if (($number  >=3600) and ($number <=86400)){$t = $number/3600;$n = sprintf("%01.2f", $t); echo $n."h";}
		if ($number  >86400){$t = $number/86400;$n = sprintf("%01.2f", $t);echo $n." day";}
		echo "</td><td>$cViruser</td>
		<td>".nl2br(substr($description,0,1000))."</td><td>$mark</td>
		<td><a href='?do=rqStatus&sta=detected&id=$id'>Up</a>/<a href='?do=rqStatus&sta=undetected&id=$id'>Down</a></td></tr>";
	}	
	echo "</table>";
}

//SET UP/Undetected status virus list
$url = 'mantis/clab.php?do=showlistvr'; 
if (($do == rqStatus) and ($sta == detected))
{	
	$id = $_GET['id'];
	$mark = 'detected';
	$time = time();
	mysql_query("UPDATE `bugtracker`.`mantis_malware_file_table` SET `mark` ='detected',`date_complete`=$time WHERE `mantis_malware_file_table`.`id` =$id");
	echo '
	<b>SECURITY RESPONSE<br><br>
	<table border=0 cellpadding=0 cellspacing=0 style="border-collapse:collapse"><tr>
	<form action="?do=send2" method="post">
	<td>Risk level</td><td><input type="mRisk"  name="mRisk" /></td></tr><tr>
	<td>Malware name:</td><td><input type="mName"  name="mName" /></td></tr><tr>
	<td>Type</td><td><input type="mType" name="mType" /></td></tr><tr>
	<td>Infection Length</td><td><input type="mLeng" name="mLeng" /></td></tr><tr>
	<td>Systems Affected</td><td><textarea name="mSysaff" type="mSysaff" cols="44" rows="5"></textarea></td></tr><tr>
	<td>Describe</td><td><textarea name="mDes" type="mDes" cols="44" rows="5"></textarea></td></tr><tr>
	<td></td><td><input type="submit" value="Send mail from CMCLab" /></td>
	</tr></table>
	</form>';	
}

//Send malware information detected to Senders
if ($do == send2)
{		
		$mRick = $_POST['mRisk'];
		$mName = $_POST['mName'];
		$mDis = time();
		$mType = $_POST['mType'];
		$mLeng = $_POST['mLeng'];
		$mSysaff = $_POST['mSysaff'];
		$mDes = $_POST['mDes'];
		mysql_query("insert into `mantis_malware_detected` 
			(mName,mType,mLeng,mRisk,mSysaff,mDes,mDis) values ('$mName','$mType','$mLeng','$mRisk','$mSysaff','$mDes','$mDis')");
			$qrSL = mysql_query("select id,filename,description,file_type,folder,filesize,date_added, date_complete, from_unixtime(date_added),senderName,senderMail,senderPhone,mark,cViruser,from_unixtime(date_complete) from mantis_malware_file_table");
	while ($row = mysql_fetch_array($qrSL))
	{
		$fn = $row['filename'];
		$sdMail = $row['senderMail'];
		$sdName = $row['senderName'];
		$dtAdd = $row['from_unixtime(date_added)'];
		include("mail_report_sender.php");	
	}
	header("location: /$url");
}

if (($do == rqStatus) and ($sta == undetected))
{	
	$id = $_GET['id'];
	$mark = 'undetected';
	$time = time();
	mysql_query("UPDATE `bugtracker`.`mantis_malware_file_table` SET `mark` ='undetected', `date_complete` =$time  WHERE `mantis_malware_file_table`.`id` =$id");
	header("location: /$url");
}

//Show list virus detected
if ($do == mDetected)
{
	$qrmDetected = mysql_query("SELECT id,mName,mType,mLeng,mRisk,mSysaff,mDes,from_unixtime(mDis) from mantis_malware_detected");
	echo "<table border=1 cellpadding=0 cellspacing=0 style='border-collapse:collapse' align=center>";
	echo "<tr><td><b>ID</td><td><b>Risk Level</td><td width=200><b>Name</td><td td width=200><b>Type</td><td><b>Protected</td></tr>";
	$run = 0;
	while ($row = mysql_fetch_array($qrmDetected))
	{
		$run++;
		$id = $row['id'];
		$dRisk = $row['mRisk'];
		$dName = $row['mName'];
		$dDis =  $row['from_unixtime(mDis)'];
		$dType = $row['mType'];
		$dLeng = $row['mLeng'];
		$dSysaff = $row['mSysaff'];
		$dDes = $row['mDes'];
	
	if ($id % 2) { $class='odd';} else {$class='even';}  
		echo "
		<tr><td class=$class>$run</td><td class=$class>"; 
		for ($i=1;$i<=$dRisk;$i++)
		{ echo "<table border=0 cellpadding=5 cellspacing=1 style='border: 0px solid black; float: left; width: 4%; height: 1px'>
		<tr><td bgcolor=red></td><tr></table>";}
		for ($d=$dRisk+1;$d<=5;$d++)
		{ echo "<table border=0 cellpadding=5 cellspacing=1 style='border: 0px solid black; float: left; width: 4%; height: 1px'>
		<tr><td bgcolor=black></td><tr></table>";}
		echo "</td><td class=$class><a href=?do=mDetail&order=$dName>$dName</a></td><td class=$class>$dType</td><td class=$class>$dDis</td></tr>";
	}
	echo "</table>";
}
?>
<?php
	html_page_bottom();